# Maintainer: Manuel Naranjo <naranjo.manuel@gmail.com>

_realname=qt-solutions

pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=r47.ad9bc46
pkgrel=1
pkgdesc='Qt5 various components (mingw-w64)'
url='https://qt.gitorious.org/qt-solutions'
arch=('any')
license=('bsd')
depends=("${MINGW_PACKAGE_PREFIX}-qt5")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "git")
options=('docs' 'staticlibs' '!strip') # 'debug' '!strip'
source=("${_realname}"::"git+https://github.com/qtproject/qt-solutions.git"
        '0001-Don-t-install-the-libraries-in-win32.patch')
sha256sums=('SKIP'
            'SKIP')

_components="qtpropertybrowser qtservice qtsingleapplication"
pkgver() {
  cd "$srcdir/$_realname"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd ${srcdir}/${_realname}
  git reset --hard origin/master
  patch -p1 < ../0001-Don-t-install-the-libraries-in-win32.patch
}

build() {
  local cur=
  for cur in ${_components}; do
    plain "Building ${cur} ..."
    local _variant=
    for _variant in debug release; do
      cd ${srcdir}/${_realname}/${cur}
      ./configure -library

      ${MINGW_PREFIX}/bin/qmake \
        ./${cur}.pro \
        CONFIG+=${_variant}
      make
    done
  done
}

package() {
  mkdir -p ${pkgdir}${MINGW_PREFIX}/{bin,include,lib}
  local cur=
  for cur in ${_components}; do
    plain "Installing ${cur} ..."
    cd ${srcdir}/${_realname}/${cur}
    cp -f lib/*.dll ${pkgdir}${MINGW_PREFIX}/bin
    cp -f lib/*.a ${pkgdir}${MINGW_PREFIX}/lib

    local _headers=( $(find ${srcdir}/${_realname}/${cur}/src -maxdepth 1 -type f ! \( -iname "*.cpp" -o -iname "*.pri" \) ) )
    cp -f ${_headers[@]} ${pkgdir}${MINGW_PREFIX}/include/
  done
}
